package br.com.salaodebeleza.view;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;
import br.gov.frameworkdemoiselle.annotation.NextView;
import br.gov.frameworkdemoiselle.annotation.PreviousView;
import br.gov.frameworkdemoiselle.stereotype.ViewController;
import br.gov.frameworkdemoiselle.template.AbstractListPageBean;
import br.gov.frameworkdemoiselle.transaction.Transactional;
import br.com.salaodebeleza.business.TbAgendaBC;
import br.com.salaodebeleza.domain.TbAgenda;
import br.com.salaodebeleza.util.TbAgendaDataModel;

@ViewController
@NextView("./tbAgenda_edit.jsf")
@PreviousView("./tbAgenda_list.jsf")
public class TbAgendaListMB extends AbstractListPageBean<TbAgenda, Long> {

	private static final long serialVersionUID = 1L;

	@Inject
	private TbAgendaBC tbAgendaBC;
	
	private TbAgenda agenda = new TbAgenda();
	
	@Override
	protected List<TbAgenda> handleResultList() {
		return this.tbAgendaBC.findAll();
	}
	
	@Transactional
	public String deleteSelection() {
		boolean delete;
		for (Iterator<Long> iter = getSelection().keySet().iterator(); iter.hasNext();) {
			Long id = iter.next();
			delete = getSelection().get(id);
			if (delete) {
				tbAgendaBC.delete(id);
				iter.remove();
			}
		}
		return getPreviousView();
	}
	
	public TbAgendaDataModel getAgendaDia() {
		List<TbAgenda> list = null;
		list = tbAgendaBC.findAgendaDia();
		//Collections.sort(list);
		return new TbAgendaDataModel(list);
	}

	public TbAgenda getAgenda() {
		return agenda;
	}

	public void setProposta(TbAgenda agenda) {
		this.agenda = agenda;
	}
	
	

}